package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.DownstreamUserDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.DownstreamUserInfo;
import com.sls.game.querybean.DownstreamUserQuery;

@Repository("downstreamUserDAO")
public class DownstreamUserDAOImpl extends SuperDAO<DownstreamUserInfo>
		implements DownstreamUserDAO {

	@Override
	public void insert(DownstreamUserInfo userInfo) {
		this.getSqlSession().insert(
				"mybatis.xml.DownstreamUserInfoMapper.insert", userInfo);
	}

	@Override
	public void update(DownstreamUserInfo userInfo) {
		this.getSqlSession().update(
				"mybatis.xml.DownstreamUserInfoMapper.update", userInfo);
	}

	@Override
	public DownstreamUserInfo queryUserByUserNO(String userNO) {
		DownstreamUserInfo info = this.getSqlSession().selectOne(
				"mybatis.xml.DownstreamUserInfoMapper.queryUserByUserNO",
				userNO);
		return info;
	}

	@Override
	public Pagination<DownstreamUserInfo> queryDownstreamUser(
			DownstreamUserQuery userQuery) {
		Integer rows = this.queryRowCount(userQuery);
		userQuery.calculate();
		List<DownstreamUserInfo> list = this.queryUserInfoList(userQuery);
		Pagination<DownstreamUserInfo> page = super.queryPagination(rows, list,
				userQuery);
		return page;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(DownstreamUserQuery userQuery) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.DownstreamUserInfoMapper.queryUserInfoRow",
				userQuery);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param goodsManageInfo
	 * @return
	 */
	private List<DownstreamUserInfo> queryUserInfoList(
			DownstreamUserQuery userQuery) {
		List<DownstreamUserInfo> list = this.getSqlSession().selectList(
				"mybatis.xml.DownstreamUserInfoMapper.queryUserInfoList",
				userQuery);
		return list;
	}

	@Override
	public DownstreamUserInfo queryUserById(String id) {
		DownstreamUserInfo info = this.getSqlSession().selectOne(
				"mybatis.xml.DownstreamUserInfoMapper.queryUserById", id);
		return info;
	}

	/**
	 * 下游用户密钥查询
	 * 
	 * @param userInfo
	 * @return
	 */
	@Override
	public String queryUserSecretKey(DownstreamUserInfo userInfo) {
		String secretKey = null;
		secretKey = this.getSqlSession().selectOne(
				"mybatis.xml.DownstreamUserInfoMapper.queryUserSecretKey",
				userInfo);
		return secretKey;
	}

	/**
	 * 查询腾讯Q币工号
	 * 
	 * @param userNo
	 * @return
	 */
	@Override
	public DownstreamUserInfo queryTencentAccount(String userNo) {
		DownstreamUserInfo userInfo = null;
		userInfo = this.getSqlSession().selectOne(
				"mybatis.xml.DownstreamUserInfoMapper.queryTencentAccount",
				userNo);
		return userInfo;
	}

	/**
	 * 根据模板编号，查询记录
	 * 
	 * @param templateCode
	 * @return
	 */
	@Override
	public List<DownstreamUserInfo> queryInfoByTemplateCode(DownstreamUserInfo user) {
		List<DownstreamUserInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.DownstreamUserInfoMapper.queryInfoByTemplateCode",
				user);
		return list;
	}
}
